import sys
#sys.path.append("/home/lips/code/version1/graph")
sys.path.append("/home/raghavendra/code/version1/graph")
from graph import graph
from Tkinter import *
import tkMessageBox
import tkSimpleDialog
import Tkinter as tk

class gui:
	root = Tk()
	frame = None
	canvas = None
	mainMenu = None
	rightMenu = None
	fileMenu = None
	editMenu = None
	helpMenu = None
	graph = None
	idToNode = {}
	idToEdge = {}
	idToText = {}
	currentNode = None
	currentType = None
	canAddNode = False

	def temp(self):
		print "hello"

	def quit(self):
		if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
			self.root.destroy()

	def __init__(self, graph):
		self.graph = graph
		self.root.protocol("WM_DELETE_WINDOW", self.quit)
		self.frame = Frame(self.root,width=1000,height=670)
		#self.frame.bind("<Button-1>",self.callback)
		self.frame.pack()
		self.makeCanvas()
		#self.makeMenu()

	def makeCanvas(self):
		self.canvas = Canvas(self.frame, width=1000, \
				height=670, relief=SUNKEN,\
				bg="white", bd=2)
		self.canvas.pack()
		#self.canvas.bind("<Button-3>",self.do_popup)
		#self.canvas.bind("<Button-1>",self.left_callback)
		#self.rightMenu = Menu(self.frame, tearoff=0)
		#self.rightMenu.add_command(label="Remove",command=self.remove_node_callback)
		#self.rightMenu.add_command(label="Add"  ,command=self.add_node_callback)


	def makeMenu(self):
		self.mainMenu = Menu(self.root)
		self.root.config(menu=self.mainMenu)
		self.fileMenu = Menu(self.mainMenu, tearoff=0)
		self.fileMenu.add_cascade(label="New",command=self.temp)
		self.fileMenu.add_cascade(label="Open",command=self.temp)
		self.fileMenu.add_separator()
		self.fileMenu.add_cascade(label="Exit",command=self.quit)
		self.mainMenu.add_cascade(label="File",menu=self.fileMenu )
		self.editMenu = Menu(self.mainMenu, tearoff=0)
		self.editMenu.add_cascade(label="Node",command=self.temp)
		self.editMenu.add_cascade(label="Edge",command=self.temp)
		self.mainMenu.add_cascade(label="Edit",menu=self.editMenu )

	

	def do_popup(self,event):
		'''try:
		        self.currentType = self.canvas.type(CURRENT)
			if self.canvas.type(CURRENT) == "rectangle":
				self.rightMenu.tk_popup(event.x_root, event.y_root, 0)
				tags = self.canvas.itemcget(CURRENT,"tags")
				self.currentNode = (tags.split(" ")[0]).strip()
				self.canAddNode = True #TODO: make it true and handle edge addition
			elif self.canvas.type(CURRENT) == "line":
				self.rightMenu.tk_popup(event.x_root, event.y_root, 0)
				tags = self.canvas.itemcget(CURRENT,"tags")
				print tags
				self.currentNode = (tags.split(" ")[0]).strip()
				self.canAddNode = False
			else:
				self.rightMenu.tk_popup(event.x_root, event.y_root, 0)
				self.canAddNode = True
		finally:
			self.rightMenu.grab_release()'''





graph_obj = graph(False, False)
graph_obj.create(['1 3','2 1', '3 4', '4 1'], 10)
graph_obj.display()

gui_obj = gui(graph_obj)




